package com.mcms.web;

import java.io.IOException;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.mcms.service.CustomCheckService;
import com.mcms.service.dw.AddCustomService;
import com.mcms.service.dw.ImgUploadService;

/**
 * 为渠道部门的客户信息录入和照片上传提供服务
 * @author leef
 */
public class TransactionServlet extends HttpServlet implements Servlet {

	private static final long serialVersionUID = 1L;
	
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		String actionType = request.getParameter("actionType");
		String check = request.getParameter("check");
		
		HttpSession session = request.getSession(false);
		System.out.println("servlet---------"+session.getId());
		session.setAttribute("user", "servlet");
		
		
		/**登陆页跳转*/
		if(actionType!=null && actionType.trim().length()>0){
			if(actionType.equals("addCustom_qd") || actionType.equals("addCustom_fz")){
				
				// 校验标记置为true时，表示进行校验
				if(check!=null && check.trim().length()>0 && check.equals("true")){
					
					// 录入过程中校验是否已经存在
					new CustomCheckService().execute(request);
				}else{
					// 渠道部门的录入
					new AddCustomService().execute(request);
				}
			}else if(actionType.equals("imgUpload")){
				
				// 图片上传处理
				String basePath = getServletContext().getRealPath("/");
				request.setAttribute("basePath", basePath);//本系统根目录所在的物理绝对位置：运行时目录path
				new ImgUploadService().execute(request);
			}
			request.getRequestDispatcher("./mcms/result.jsp").forward(request, response);
		}
	}
	
	
}
